package com.example.cotroller;

import com.example.pojo.ResponseData;
import com.example.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/api")
public class BlogController {

    @Autowired
    private BlogService blogService;

    @GetMapping("/backend")
    @ResponseBody
    public ResponseData getBlog() {
        List blogList=blogService.selectBlog();
        ResponseData res;
        if (blogList.isEmpty()){
            res = new ResponseData(500,"查询出错","");
        }else{
            res = new ResponseData(200,"查询成功",blogList);
        }
        return res;
    }
}